//
// Created by 朱语 on 2022/9/9.
//

#include "Stack.h"
using namespace std;

template <class T>
Stack<T>::Stack(){
    rear = -1;
}

template <class T>
bool Stack<T>::push(const T& item) {
    this->_stack.template emplace_back(item);
    rear++;
    if(_stack[rear] == item)
        return true;
    return false;
}

template <class T>
bool Stack<T>::pop() {
    if(rear == 0)
        return false;
    rear--;
    _stack.pop_back();
    return true;
}

template <class T>
T Stack<T>::top() const{
    if(rear < 0){
        throw std::out_of_range("Stack is empty!");
    }
    return _stack[rear];
}

template <class T>
bool Stack<T>::empty() {
    return rear == -1;
}

template <class T>
void Stack<T>::clear() {
    rear = -1;
}